<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowe');

class Main extends CI_Controller {

    function __construct() { //inisialisasi library dan helper yang perlu di load
        parent::__construct();
        $this->load->model('berbah');
    }

    function index() {
        $data['title'] = 'Welcome';
        $data['isi'] = $this->berbah->get_sys();
        $this->load->view('main', $data);
    }

    function login() {
        $log = array(
            'username' => $this->input->post('name'),
            'password' => $this->encrypt->sha1($this->input->post('pass'))
        );
        $login = $this->berbah->login($log); //kirim ke database
        if ($login->privilege_id == 1) {
            $ses = array(
                'username' => $login->username,
                'nama' => $login->nama,
                'login' => TRUE,
                'privilege' => 1
            );
            $this->session->set_userdata($ses);
            redirect('petugas');
        } elseif ($login->privilege_id == 2) {
            $ses = array(
                'username' => $login->username,
                'nama' => $login->nama,
                'login' => TRUE,
                'privilege' => 2
            );
            $this->session->set_userdata($ses);
            redirect('petugas');
        } else {
            redirect();
        }
    }
    
    function logout(){
        $this->session->sess_destroy();
        redirect();
    }

}

?>
